Skip to content

Conversation

@akodanev
Copy link
Contributor

This PR addresses two issues related to glibc-specific usage in the tests to ensure they can be built with musl libc too:

  • the use of __GNUC_PREREQ macro from features.h - replaced with GNUC_PREREQ that is provided by shim.h and implements the same functionality.
  • and the use of execinfo.h (backtrace functions) - musl libc does not provide the backtrace functions in its implementation. These functions are typically provided by glibc's execinfo.h. As a fallback for musl-based systems, support linking against the external libunwind library and using dladdr() to obtain similar stack trace info. Note that the usage of dladdr() is similar to that of backtrace_symbols in glibc, and it can be used with glibc as well.

@akodanev akodanev force-pushed the ak/fix-musl-tests-build branch 2 times, most recently from 4c46335 to 8e04ef6 Compare September 25, 2025 07:23
@akodanev
Copy link
Contributor Author

Only mkosi/boot fedora* checks fail. All are as follows:

ld -o shimx64.so --hash-style=sysv -nostdlib -znocombreloc -T /work/src/elf_x86_64_efi.lds -shared -Bsymbolic -Lgnu-efi/x86_64/gnuefi -Lgnu-efi/x86_64/lib -LCryptlib -LCryptlib/OpenSSL gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o --build-id=sha1  --no-undefined shim.o globals.o memattrs.o mok.o netboot.o cert.o dp.o loader-proto.o tpm.o version.o errlog.o sbat.o sbat_data.o sbat_var.o pe.o pe-relocate.o httpboot.o csv.o load-options.o utils.o verify.o Cryptlib/libcryptlib.a Cryptlib/OpenSSL/libopenssl.a lib/lib.a gnu-efi/x86_64/lib/libefi.a gnu-efi/x86_64/gnuefi/libgnuefi.a -lefi -lgnuefi --start-group Cryptlib/libcryptlib.a Cryptlib/OpenSSL/libopenssl.a --end-group /usr/lib/gcc/x86_64-redhat-linux/15/libgcc.a lib/lib.a
gcc -std=gnu11 -Og -g3 -Wall -Wextra -Wno-missing-field-initializers -Werror -o post-process-pe /work/src/post-process-pe.c
objcopy -D -j .text -j .sdata -j .data -j .data.ident \
	-j .dynamic -j .rodata -j .rel* \
	-j .rela* -j .dyn -j .reloc -j .eh_frame \
	-j .vendor_cert -j .sbat -j .sbatlevel \
	--file-alignment 0x1000 \
	--target efi-app-x86_64 shimx64.so shimx64.efi
objcopy: shimx64.so: file format not recognized
make: *** [/work/src/Makefile:280: shimx64.efi] Error 1

This is unrelated to the test build in the PR, but rather to recent changes in f44 that may be possible in binutils (2.45.50-3.fc44).

@akodanev
Copy link
Contributor Author

I checked the previous version in f44, downgrading from 2.45.50-3.fc44 to 2.45-1.fc43 fixes objcopy.

include/test.mk Outdated
BACKTRACE_DEFINES ?=

INCL_LIBUNWIND = '\#include <libunwind.h>'
HAVE_LIBUNWIND := $(shell echo $(INCL_LIBUNWIND) | $(CC) -E - >/dev/null 2>&1 && echo 1 || echo 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand this means it will end up linking with libunwind even if it just happens to be installed, even when using glibc? If so, that's not great, could it be made in an explicit makefile env var to set instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is a safer option, BTW. So when building for musl to enable backtrace in the tests, USE_LIBUNWIND should be explicitly passed:

ifneq ($(origin USE_LIBUNWIND), undefined)
ARCH_DEFINES += -DHAVE_LIBUNWIND
LIBS += -lunwind
endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few changes to the naming and rearranged the ifdef checks. Now, only providing ENABLE_LIBUNWIND explicitly enables linking with libunwind and the use of fallback behavior in print_traceback().

Musl libc does not provide the backtrace functions in its implementation.
These functions are typically provided by glibc's <execinfo.h>.

As a fallback for musl-based systems, support linking against the external
libunwind library and using dladdr() to obtain similar stack trace info.

Note that the usage of dladdr() is similar to that of backtrace_symbols in
glibc, and it can be used with glibc as well.

Signed-off-by: Alexey Kodanev <[email protected]>
GNUC_PREREQ macro is provided by shim.h and implements the same functionality.

Signed-off-by: Alexey Kodanev <[email protected]>
@akodanev akodanev force-pushed the ak/fix-musl-tests-build branch from 8e04ef6 to 6f6e71c Compare September 26, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants